package com.iot.commons;

import com.iot.model.BaseModel;

import javax.validation.constraints.Min;
import java.io.Serializable;

public class PageRequest extends BaseModel implements Serializable {

    private static final int DEFAULT_PAGE_SIZE = 10;

    private int pageIndex;

    @Min(value = 1, message = "分页参数不合法，页面大小不能小于1")
    private int pageSize = DEFAULT_PAGE_SIZE;

    public PageRequest() {

    }

    public PageRequest(int pageIndex, int pageSize) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getOffset(){
        return (pageIndex - 1) * pageSize;
    }

    @Override
    public String toString() {
        return "PageRequest{" +
                "pageIndex=" + pageIndex +
                ", pageSize=" + pageSize +
                '}';
    }
}
